﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
using System.Security.Cryptography;
using System.Data;
using System.Reflection;
using System.ComponentModel;
namespace PTA
{
    public static class Convert
    {
        internal static System.Globalization.CultureInfo cnci = new System.Globalization.CultureInfo("zh-cn");

        #region 判断是否指定类型

        public static object DBNull
        {
            get
            {
                return System.Convert.DBNull;
            }
        }
        public static bool IsDBNull(object value)
        {
            return System.Convert.IsDBNull(value);
        }

        [Description("同时判断是否Null或DBNull")]
        public static bool IsNull(object value)
        {
            return value == null || System.Convert.IsDBNull(value);
        }

        public static bool IsInt(string value)
        {
            int t = 0;
            return int.TryParse(value, out t);
        }

        public static bool IsIntGreateThanZero(string value)
        {
            int t = 0;
            if (int.TryParse(value, out t))
            {
                return t > 0;
            }
            return false;
        }

        public static bool IsLong(string value)
        {
            long t = 0;
            return long.TryParse(value, out t);
        }

        public static bool IsLongGreateThanZero(string value)
        {
            long t = 0;
            if (long.TryParse(value, out t))
            {
                return t > 0;
            }
            return false;
        }

        public static bool IsFloat(string value)
        {
            float t = 0;
            return float.TryParse(value, out t);
        }

        public static bool IsFloatGreateThanZero(string value)
        {
            float t = 0;
            if (float.TryParse(value, out t))
            {
                return t > 0;
            }
            return false;
        }

        public static bool IsDouble(string value)
        {
            double t = 0;
            return double.TryParse(value, out t);
        }

        public static bool IsDoubleGreateThanZero(string value)
        {
            double t = 0;
            if (double.TryParse(value, out t))
            {
                return t > 0;
            }
            return false;
        }

        public static bool IsDate(string value)
        {
            return Regular.CheckString(value, ValidateType.Date, false);
        }

        public static bool IsTime(string value)
        {
            return Regular.CheckString(value, ValidateType.Time, false);
        }

        public static bool IsDateTime(string value)
        {
            return Regular.CheckString(value, ValidateType.DateTime, false);
        }

        /// <summary>
        /// 严格的用逗号分隔的整数字符串
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static bool IsStrictNumber(string value)
        {
            return Regular.CheckString(value, ValidateType.StrictNumberJoin, false);
        }

        public static bool IsStrictString(string value)
        {
            return Regular.CheckString(value, ValidateType.StrictStringJoin, false);
        }

        public static bool IsEmail(string value)
        {
            return Regular.CheckString(value, ValidateType.Email, false);
        }

        /// <summary>
        /// 是否是以字母开头的以数字字母和下划线结尾的长度的6-20个字符的字符串
        /// </summary>
        public static bool IsLoginName(string value)
        {
            return Regular.CheckString(value, ValidateType.UserId, false);
        }

        public static bool IsMobile(string value)
        {
            return Regular.CheckString(value, ValidateType.Mobile, false);
        }

        public static bool IsGuid(string value)
        {
            return Regular.CheckString(value, ValidateType.Guid, false);
        }

        public static bool IsNullOrEmpty(string value)
        {
            return string.IsNullOrEmpty(value);
        }

        public static bool IsNullOrWhiteSpace(string value)
        {
            return string.IsNullOrWhiteSpace(value);
        }

        public static bool IsNumeric(string value)
        #endregion

        #region TYPE
        public static object ChangeType(object value, Type conversionType)
        {
            if (conversionType.IsEnum)
            {
                if (value is Enum || value is int || value is long || value is short)
                {
                    return Enum.Parse(conversionType, Convert.ToInt32(value).ToString(), true);
                }
                try
                {
                    return Enum.Parse(conversionType, value.ToString());
                }
                catch (ArgumentException ex)
                {
                    var field = conversionType.GetFields().Find(x => x.HasAttribute<DescriptionAttribute>() && x.GetAttribute<DescriptionAttribute>().Description.Equals(value.ToString()));
                    if (field != null)
                    {
                        return field.GetValue(null);
                    }
                    throw ex;
                }
            }
            if (conversionType == typeof(Guid) && IsGuid(value.ToString()))
            {
                return Guid.Parse(value.ToString());
            }
            return System.Convert.ChangeType(value, conversionType);
        }
        public static object ChangeType(object value, TypeCode typeCode)
        {
            return System.Convert.ChangeType(value, typeCode);
        }
        public static object ChangeType(object value, Type conversionType, IFormatProvider provider)
        {
            return System.Convert.ChangeType(value, conversionType, provider);
        }
        public static object ChangeType(object value, TypeCode typeCode, IFormatProvider provider)
        {
            return System.Convert.ChangeType(value, typeCode, provider);
        }
        public static TypeCode GetTypeCode(object value)
        {
            return System.Convert.GetTypeCode(value);
        }
        public static T ChangeType<T>(object value)
        {
            return (T)ChangeType(value, typeof(T));
        }
        public static T ChangeType<T>(object value, IFormatProvider provider)
        {
            return (T)System.Convert.ChangeType(value, typeof(T), provider);
        }
        #endregion

        #region BASE64
        public static byte[] FromBase64CharArray(char[] inArray, int offset, int length)
        {
            return System.Convert.FromBase64CharArray(inArray, offset, length);
        }
        public static byte[] FromBase64String(string s)
        {
            return System.Convert.FromBase64String(s);
        }
        public static int ToBase64CharArray(byte[] inArray, int offsetIn, int length, char[] outArray, int offsetOut)
        {
            return System.Convert.ToBase64CharArray(inArray, offsetIn, length, outArray, offsetOut);
        }
        public static int ToBase64CharArray(byte[] inArray, int offsetIn, int length, char[] outArray, int offsetOut, Base64FormattingOptions options)
        {
            return System.Convert.ToBase64CharArray(inArray, offsetIn, length, outArray, offsetOut, options);
        }
        public static string ToBase64String(byte[] inArray)
        {
            return System.Convert.ToBase64String(inArray);
        }
        public static string ToBase64String(byte[] inArray, Base64FormattingOptions options)
        {
            return System.Convert.ToBase64String(inArray, options);
        }
        public static string ToBase64String(byte[] inArray, int offset, int length)
        {
            return System.Convert.ToBase64String(inArray, offset, length);
        }
        public static string ToBase64String(byte[] inArray, int offset, int length, Base64FormattingOptions options)
        {
            return System.Convert.ToBase64String(inArray, offset, length, options);
        }
        #endregion

        #region BOOLEAN
        public static bool ToBoolean(bool value)
        {
            return System.Convert.ToBoolean(value);
        }
        public static bool ToBoolean(byte value)
        {
            return System.Convert.ToBoolean(value);
        }
        public static bool ToBoolean(char value)
        {
            return System.Convert.ToBoolean(value);
        }
        public static bool ToBoolean(DateTime value)
        {
            return System.Convert.ToBoolean(value);
        }
        public static bool ToBoolean(decimal value)
        {
            return System.Convert.ToBoolean(value);
        }
        public static bool ToBoolean(double value)
        {
            return System.Convert.ToBoolean(value);
        }
        public static bool ToBoolean(float value)
        {
            return System.Convert.ToBoolean(value);
        }
        public static bool ToBoolean(int value)
        {
            return System.Convert.ToBoolean(value);
        }
        public static bool ToBoolean(long value)
        {
            return System.Convert.ToBoolean(value);
        }
        public static bool ToBoolean(object value)
        {
            if (value is string)
            {
                return ToBoolean((string)value);
            }
            return System.Convert.ToBoolean(value);
        }
        public static bool ToBoolean(sbyte value)
        {
            return System.Convert.ToBoolean(value);
        }
        public static bool ToBoolean(short value)
        {
            return System.Convert.ToBoolean(value);
        }
        public static bool ToBoolean(string value)
        {
            if (value == null)
            {
                return false;
            }
            value = value.Trim();
            var t = new string[] { "true", "t", "yes", "y", "1" };
            if (t.Exists(item => value.Equals(item, StringComparison.OrdinalIgnoreCase)))
            {
                return true;
            }
            if (IsInt(value))
            {
                return Convert.ToInt32(value) > 0;
            }
            var f = new string[] { "false", "f", "no", "n", "0" };
            if (f.Exists(item => value.Equals(item, StringComparison.OrdinalIgnoreCase)))
            {
                return false;
            }
            return System.Convert.ToBoolean(value);
        }
        public static bool ToBoolean(uint value)
        {
            return System.Convert.ToBoolean(value);
        }
        public static bool ToBoolean(ulong value)
        {
            return System.Convert.ToBoolean(value);
        }
        public static bool ToBoolean(ushort value)
        {
            return System.Convert.ToBoolean(value);
        }
        public static bool ToBoolean(object value, IFormatProvider provider)
        {
            return System.Convert.ToBoolean(value, provider);
        }
        public static bool ToBoolean(string value, IFormatProvider provider)
        {
            return System.Convert.ToBoolean(value, provider);
        }

        #region 下面的转换方法会在出现不能转换或错误时,使用默认值
        public static bool ToBoolean(string value, bool defaultValue)
        {
            if (IsNull(value) || (value is string && string.IsNullOrWhiteSpace((string)value)))
            {
                return defaultValue;
            }
            try
            {
                return ToBoolean(value);
            }
            catch
            {
                return defaultValue;
            }
        }

        public static bool ToBoolean(object value, bool defaultValue)
        {
            if (IsNull(value) || (value is string && string.IsNullOrWhiteSpace((string)value)))
            {
                return defaultValue;
            }
            try
            {
                return ToBoolean(value);
            }
            catch
            {
                return defaultValue;
            }
        }
        #endregion

        #region 下面的方法将字符串转换为可空类型
        public static Nullable<bool> ToBoolean(string value, bool? defaultValue = false)
        {
            return ToBoolean(value, defaultValue, defaultValue);
        }
        public static Nullable<bool> ToBoolean(string value, bool? nullValue = null, bool? errorValue = false)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                return nullValue;
            }
            try
            {
                return ToBoolean(value);
            }
            catch
            {
                return errorValue;
            }
        }
        #endregion
        #endregion

        #region BYTE
        public static byte ToByte(bool value)
        {
            return System.Convert.ToByte(value);
        }
        public static byte ToByte(byte value)
        {
            return System.Convert.ToByte(value);
        }
        public static byte ToByte(char value)
        {
            return System.Convert.ToByte(value);
        }
        public static byte ToByte(DateTime value)
        {
            return System.Convert.ToByte(value);
        }
        public static byte ToByte(decimal value)
        {
            return System.Convert.ToByte(value);
        }
        public static byte ToByte(double value)
        {
            return System.Convert.ToByte(value);
        }
        public static byte ToByte(float value)
        {
            return System.Convert.ToByte(value);
        }
        public static byte ToByte(int value)
        {
            return System.Convert.ToByte(value);
        }
        public static byte ToByte(long value)
        {
            return System.Convert.ToByte(value);
        }
        public static byte ToByte(object value)
        {
            return System.Convert.ToByte(value);
        }
        public static byte ToByte(sbyte value)
        {
            return System.Convert.ToByte(value);
        }
        public static byte ToByte(short value)
        {
            return System.Convert.ToByte(value);
        }
        public static byte ToByte(string value)
        {
            return System.Convert.ToByte(value);
        }
        public static byte ToByte(uint value)
        {
            return System.Convert.ToByte(value);
        }
        public static byte ToByte(ulong value)
        {
            return System.Convert.ToByte(value);
        }
        public static byte ToByte(ushort value)
        {
            return System.Convert.ToByte(value);
        }
        public static byte ToByte(object value, IFormatProvider provider)
        {
            return System.Convert.ToByte(value, provider);
        }
        public static byte ToByte(string value, IFormatProvider provider)
        {
            return System.Convert.ToByte(value, provider);
        }
        public static byte ToByte(string value, int fromBase)
        {
            return System.Convert.ToByte(value, fromBase);
        }
        #endregion

        #region CHAR
        public static char ToChar(bool value)
        {
            return System.Convert.ToChar(value);
        }
        public static char ToChar(byte value)
        {
            return System.Convert.ToChar(value);
        }
        public static char ToChar(char value)
        {
            return System.Convert.ToChar(value);
        }
        public static char ToChar(DateTime value)
        {
            return System.Convert.ToChar(value);
        }
        public static char ToChar(decimal value)
        {
            return System.Convert.ToChar(value);
        }
        public static char ToChar(double value)
        {
            return System.Convert.ToChar(value);
        }
        public static char ToChar(float value)
        {
            return System.Convert.ToChar(value);
        }
        public static char ToChar(int value)
        {
            return System.Convert.ToChar(value);
        }
        public static char ToChar(long value)
        {
            return System.Convert.ToChar(value);
        }
        public static char ToChar(object value)
        {
            return System.Convert.ToChar(value);
        }
        public static char ToChar(sbyte value)
        {
            return System.Convert.ToChar(value);
        }
        public static char ToChar(short value)
        {
            return System.Convert.ToChar(value);
        }
        public static char ToChar(string value)
        {
            return System.Convert.ToChar(value);
        }
        public static char ToChar(uint value)
        {
            return System.Convert.ToChar(value);
        }
        public static char ToChar(ulong value)
        {
            return System.Convert.ToChar(value);
        }
        public static char ToChar(ushort value)
        {
            return System.Convert.ToChar(value);
        }
        public static char ToChar(object value, IFormatProvider provider)
        {
            return System.Convert.ToChar(value, provider);
        }
        public static char ToChar(string value, IFormatProvider provider)
        {
            return System.Convert.ToChar(value, provider);
        }
        #endregion

        #region DATETIME
        public static DateTime ToDateTime(bool value)
        {
            return System.Convert.ToDateTime(value);
        }
        public static DateTime ToDateTime(byte value)
        {
            return System.Convert.ToDateTime(value);
        }
        public static DateTime ToDateTime(char value)
        {
            return System.Convert.ToDateTime(value);
        }
        public static DateTime ToDateTime(DateTime value)
        {
            return System.Convert.ToDateTime(value);
        }
        public static DateTime ToDateTime(decimal value)
        {
            return System.Convert.ToDateTime(value);
        }
        public static DateTime ToDateTime(double value)
        {
            return System.Convert.ToDateTime(value);
        }
        public static DateTime ToDateTime(float value)
        {
            return System.Convert.ToDateTime(value);
        }
        public static DateTime ToDateTime(int value)
        {
            return System.Convert.ToDateTime(value);
        }
        public static DateTime ToDateTime(long value)
        {
            return System.Convert.ToDateTime(value);
        }
        public static DateTime ToDateTime(object value)
        {
            return System.Convert.ToDateTime(value);
        }
        public static DateTime ToDateTime(sbyte value)
        {
            return System.Convert.ToDateTime(value);
        }
        public static DateTime ToDateTime(short value)
        {
            return System.Convert.ToDateTime(value);
        }
        public static DateTime ToDateTime(string value)
        {
            return System.Convert.ToDateTime(value);
        }
        public static DateTime ToDateTime(uint value)
        {
            return System.Convert.ToDateTime(value);
        }
        public static DateTime ToDateTime(ulong value)
        {
            return System.Convert.ToDateTime(value);
        }
        public static DateTime ToDateTime(ushort value)
        {
            return System.Convert.ToDateTime(value);
        }
        public static DateTime ToDateTime(object value, IFormatProvider provider)
        {
            return System.Convert.ToDateTime(value, provider);
        }
        public static DateTime ToDateTime(string value, IFormatProvider provider)
        {
            return System.Convert.ToDateTime(value, provider);
        }
        public static DateTime ToDateTime(string value, string format)
        {
            return DateTime.ParseExact(value, format, cnci);
        }
        public static int ToYear(DateTime value)
        {
            return value.Year;
        }
        public static int ToQuarter(DateTime value)
        {
            return value.Year * 100 + (value.Month + 2) / 3;
        }
        public static int ToMonth(DateTime value)
        {
            return value.Year * 100 + value.Month;
        }
        public static int ToWeek(DateTime value)
        {
            return System.Globalization.CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(value, System.Globalization.CalendarWeekRule.FirstDay, System.DayOfWeek.Monday);
        }
        public static int ToDate(DateTime value)
        {
            return value.Year * 10000 + value.Month * 100 + value.Day;
        }
        public static int ToHour(DateTime value)
        {
            return value.Year * 1000000 + value.Month * 10000 + value.Day * 100 + value.Hour;
        }

        #region 下面的转换方法会在出现不能转换或错误时,使用默认值
        public static DateTime ToDateTime(object value, DateTime defaultValue)
        {
            if (IsNull(value) || (value is string && string.IsNullOrWhiteSpace((string)value)))
            {
                return defaultValue;
            }
            try
            {
                return System.Convert.ToDateTime(value);
            }
            catch
            {
                return defaultValue;
            }
        }
        public static DateTime ToDateTime(object value, string defaultValue)
        {
            if (IsNull(value) || (value is string && string.IsNullOrWhiteSpace((string)value)))
            {
                return System.Convert.ToDateTime(defaultValue);
            }
            try
            {
                return System.Convert.ToDateTime(value);
            }
            catch
            {
                return System.Convert.ToDateTime(defaultValue);
            }
        }
        #endregion

        #region 下面的方法将字符串转换为可空类型
        public static Nullable<DateTime> ToDateTime(string value, DateTime? defaultValue)
        {
            return ToDateTime(value, defaultValue, defaultValue);
        }
        public static Nullable<DateTime> ToDateTime(string value, DateTime? nullValue, DateTime? errorValue)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                return nullValue;
            }
            try
            {
                return ToDateTime(value);
            }
            catch
            {
                return errorValue;
            }
        }
        #endregion


        #endregion

        #region DECIMAL
        public static decimal ToDecimal(bool value)
        {
            return System.Convert.ToDecimal(value);
        }
        public static decimal ToDecimal(byte value)
        {
            return System.Convert.ToDecimal(value);
        }
        public static decimal ToDecimal(char value)
        {
            return System.Convert.ToDecimal(value);
        }
        public static decimal ToDecimal(DateTime value)
        {
            return System.Convert.ToDecimal(value);
        }
        public static decimal ToDecimal(decimal value)
        {
            return System.Convert.ToDecimal(value);
        }
        public static decimal ToDecimal(double value)
        {
            return System.Convert.ToDecimal(value);
        }
        public static decimal ToDecimal(float value)
        {
            return System.Convert.ToDecimal(value);
        }
        public static decimal ToDecimal(int value)
        {
            return System.Convert.ToDecimal(value);
        }
        public static decimal ToDecimal(long value)
        {
            return System.Convert.ToDecimal(value);
        }
        public static decimal ToDecimal(sbyte value)
        {
            return System.Convert.ToDecimal(value);
        }
        public static decimal ToDecimal(short value)
        {
            return System.Convert.ToDecimal(value);
        }
        public static decimal ToDecimal(uint value)
        {
            return System.Convert.ToDecimal(value);
        }
        public static decimal ToDecimal(ulong value)
        {
            return System.Convert.ToDecimal(value);
        }
        public static decimal ToDecimal(ushort value)
        {
            return System.Convert.ToDecimal(value);
        }

        public static decimal ToDecimal(object value)
        {
            return System.Convert.ToDecimal(value);
        }
        public static decimal ToDecimal(string value)
        {
            return System.Convert.ToDecimal(value);
        }
        public static decimal ToDecimal(object value, IFormatProvider provider)
        {
            return System.Convert.ToDecimal(value, provider);
        }
        public static decimal ToDecimal(string value, IFormatProvider provider)
        {
            return System.Convert.ToDecimal(value, provider);
        }

        #region 下面的转换方法会在出现不能转换或错误时,使用默认值
        public static decimal ToDecimal(object value, decimal defaultValue)
        {
            if (IsNull(value) || (value is string && string.IsNullOrWhiteSpace((string)value)))
            {
                return defaultValue;
            }
            try
            {
                return System.Convert.ToDecimal(value);
            }
            catch
            {
                return defaultValue;
            }
        }
        #endregion

        #region 下面的方法将字符串转换为可空类型
        public static Nullable<decimal> ToDecimal(string value, decimal? defaultValue)
        {
            return ToDecimal(value, defaultValue, defaultValue);
        }
        public static Nullable<decimal> ToDecimal(string value, decimal? nullValue = null, decimal? errorValue = 0m)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                return nullValue;
            }
            try
            {
                return ToDecimal(value);
            }
            catch
            {
                return errorValue;
            }
        }
        #endregion

        #endregion

        #region DOUBLE
        public static double ToDouble(bool value)
        {
            return System.Convert.ToDouble(value);
        }
        public static double ToDouble(byte value)
        {
            return System.Convert.ToDouble(value);
        }
        public static double ToDouble(char value)
        {
            return System.Convert.ToDouble(value);
        }
        public static double ToDouble(DateTime value)
        {
            return System.Convert.ToDouble(value);
        }
        public static double ToDouble(decimal value)
        {
            return System.Convert.ToDouble(value);
        }
        public static double ToDouble(double value)
        {
            return System.Convert.ToDouble(value);
        }
        public static double ToDouble(float value)
        {
            return System.Convert.ToDouble(value);
        }
        public static double ToDouble(int value)
        {
            return System.Convert.ToDouble(value);
        }
        public static double ToDouble(long value)
        {
            return System.Convert.ToDouble(value);
        }
        public static double ToDouble(object value)
        {
            return System.Convert.ToDouble(value);
        }
        public static double ToDouble(sbyte value)
        {
            return System.Convert.ToDouble(value);
        }
        public static double ToDouble(short value)
        {
            return System.Convert.ToDouble(value);
        }
        public static double ToDouble(string value)
        {
            return System.Convert.ToDouble(value);
        }
        public static double ToDouble(uint value)
        {
            return System.Convert.ToDouble(value);
        }
        public static double ToDouble(ulong value)
        {
            return System.Convert.ToDouble(value);
        }
        public static double ToDouble(ushort value)
        {
            return System.Convert.ToDouble(value);
        }
        public static double ToDouble(object value, IFormatProvider provider)
        {
            return System.Convert.ToDouble(value, provider);
        }
        public static double ToDouble(string value, IFormatProvider provider)
        {
            return System.Convert.ToDouble(value, provider);
        }

        #region 下面的转换方法会在出现不能转换或错误时,使用默认值
        public static double ToDouble(object value, double defaultValue)
        {
            if (IsNull(value) || (value is string && string.IsNullOrWhiteSpace((string)value)))
            {
                return defaultValue;
            }
            try
            {
                return System.Convert.ToDouble(value);
            }
            catch
            {
                return defaultValue;
            }
        }
        #endregion

        #region 下面的方法将字符串转换为可空类型
        public static Nullable<double> ToDouble(string value, double? defaultValue = 0)
        {
            return ToDouble(value, defaultValue, defaultValue);
        }
        public static Nullable<double> ToDouble(string value, double? nullValue = null, double? errorValue = 0)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                return nullValue;
            }
            try
            {
                return ToDouble(value);
            }
            catch
            {
                return errorValue;
            }
        }
        #endregion

        #endregion

        #region INT16
        public static short ToInt16(bool value)
        {
            return System.Convert.ToInt16(value);
        }
        public static short ToInt16(byte value)
        {
            return System.Convert.ToInt16(value);
        }
        public static short ToInt16(char value)
        {
            return System.Convert.ToInt16(value);
        }
        public static short ToInt16(DateTime value)
        {
            return System.Convert.ToInt16(value);
        }
        public static short ToInt16(decimal value)
        {
            return System.Convert.ToInt16(value);
        }
        public static short ToInt16(double value)
        {
            return System.Convert.ToInt16(value);
        }
        public static short ToInt16(float value)
        {
            return System.Convert.ToInt16(value);
        }
        public static short ToInt16(int value)
        {
            return System.Convert.ToInt16(value);
        }
        public static short ToInt16(long value)
        {
            return System.Convert.ToInt16(value);
        }
        public static short ToInt16(object value)
        {
            return System.Convert.ToInt16(value);
        }
        public static short ToInt16(sbyte value)
        {
            return System.Convert.ToInt16(value);
        }
        public static short ToInt16(short value)
        {
            return System.Convert.ToInt16(value);
        }
        public static short ToInt16(string value)
        {
            return System.Convert.ToInt16(value);
        }
        public static short ToInt16(uint value)
        {
            return System.Convert.ToInt16(value);
        }
        public static short ToInt16(ulong value)
        {
            return System.Convert.ToInt16(value);
        }
        public static short ToInt16(ushort value)
        {
            return System.Convert.ToInt16(value);
        }
        public static short ToInt16(object value, IFormatProvider provider)
        {
            return System.Convert.ToInt16(value, provider);
        }
        public static short ToInt16(string value, IFormatProvider provider)
        {
            return System.Convert.ToInt16(value, provider);
        }

        public static short ToInt16(string value, FromBase fromBase)
        {
            return System.Convert.ToInt16(value, (int)fromBase);
        }

        #region 下面的转换方法会在出现不能转换或错误时,使用默认值
        public static short ToInt16(string value, short defaultValue)
        {
            if (IsNull(value) || (value is string && string.IsNullOrWhiteSpace((string)value)))
            {
                return defaultValue;
            }
            try
            {
                return System.Convert.ToInt16(value);
            }
            catch
            {
                return defaultValue;
            }
        }

        public static short ToInt16(object value, short defaultValue)
        {
            if (IsNull(value) || (value is string && string.IsNullOrWhiteSpace((string)value)))
            {
                return defaultValue;
            }
            try
            {
                return System.Convert.ToInt16(value);
            }
            catch
            {
                return defaultValue;
            }
        }
        #endregion

        #region 下面的方法将字符串转换为可空类型
        public static Nullable<short> ToInt16(string value, short? defaultValue = 0)
        {
            return ToInt16(value, defaultValue, defaultValue);
        }
        public static Nullable<short> ToInt16(string value, short? nullValue = null, short? errorValue = 0)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                return nullValue;
            }
            try
            {
                return ToInt16(value);
            }
            catch
            {
                return errorValue;
            }
        }
        #endregion
        #endregion

        #region INT32
        public static int ToInt32(bool value)
        {
            return System.Convert.ToInt32(value);
        }
        public static int ToInt32(byte value)
        {
            return System.Convert.ToInt32(value);
        }
        public static int ToInt32(char value)
        {
            return System.Convert.ToInt32(value);
        }
        public static int ToInt32(DateTime value)
        {
            return System.Convert.ToInt32(value);
        }
        public static int ToInt32(decimal value)
        {
            return System.Convert.ToInt32(value);
        }
        public static int ToInt32(double value)
        {
            return System.Convert.ToInt32(value);
        }
        public static int ToInt32(float value)
        {
            return System.Convert.ToInt32(value);
        }
        public static int ToInt32(int value)
        {
            return System.Convert.ToInt32(value);
        }
        public static int ToInt32(long value)
        {
            return System.Convert.ToInt32(value);
        }
        public static int ToInt32(object value)
        {
            return System.Convert.ToInt32(value);
        }
        public static int ToInt32(sbyte value)
        {
            return System.Convert.ToInt32(value);
        }
        public static int ToInt32(short value)
        {
            return System.Convert.ToInt32(value);
        }
        public static int ToInt32(string value)
        {
            return System.Convert.ToInt32(value);
        }
        public static int ToInt32(uint value)
        {
            return System.Convert.ToInt32(value);
        }
        public static int ToInt32(ulong value)
        {
            return System.Convert.ToInt32(value);
        }
        public static int ToInt32(ushort value)
        {
            return System.Convert.ToInt32(value);
        }
        public static int ToInt32(object value, IFormatProvider provider)
        {
            return System.Convert.ToInt32(value, provider);
        }
        public static int ToInt32(string value, IFormatProvider provider)
        {
            return System.Convert.ToInt32(value, provider);
        }

        public static int ToInt32(string value, FromBase fromBase)
        {
            return System.Convert.ToInt32(value, (int)fromBase);
        }


        #region 下面的转换方法会在出现不能转换或错误时,使用默认值
        public static int ToInt32(string value, int defaultValue)
        {
            if (IsNull(value) || (value is string && string.IsNullOrWhiteSpace((string)value)))
            {
                return defaultValue;
            }
            try
            {
                return System.Convert.ToInt32(value);
            }
            catch
            {
                return defaultValue;
            }
        }

        public static int ToInt32(object value, int defaultValue)
        {
            if (IsNull(value) || (value is string && string.IsNullOrWhiteSpace((string)value)))
            {
                return defaultValue;
            }
            try
            {
                return System.Convert.ToInt32(value);
            }
            catch
            {
                return defaultValue;
            }
        }
        #endregion

        #region 下面的方法将字符串转换为可空类型
        public static Nullable<int> ToInt32(string value, int? defaultValue = 0)
        {
            return ToInt32(value, defaultValue, defaultValue);
        }
        public static Nullable<int> ToInt32(string value, int? nullValue = null, int? errorValue = 0)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                return nullValue;
            }
            try
            {
                return ToInt32(value);
            }
            catch
            {
                return errorValue;
            }
        }
        #endregion
        #endregion

        #region INT64
        public static long ToInt64(bool value)
        {
            return System.Convert.ToInt64(value);
        }
        public static long ToInt64(byte value)
        {
            return System.Convert.ToInt64(value);
        }
        public static long ToInt64(char value)
        {
            return System.Convert.ToInt64(value);
        }
        public static long ToInt64(DateTime value)
        {
            return System.Convert.ToInt64(value);
        }
        public static long ToInt64(decimal value)
        {
            return System.Convert.ToInt64(value);
        }
        public static long ToInt64(double value)
        {
            return System.Convert.ToInt64(value);
        }
        public static long ToInt64(float value)
        {
            return System.Convert.ToInt64(value);
        }
        public static long ToInt64(int value)
        {
            return System.Convert.ToInt64(value);
        }
        public static long ToInt64(long value)
        {
            return System.Convert.ToInt64(value);
        }
        public static long ToInt64(object value)
        {
            return System.Convert.ToInt64(value);
        }
        public static long ToInt64(sbyte value)
        {
            return System.Convert.ToInt64(value);
        }
        public static long ToInt64(short value)
        {
            return System.Convert.ToInt64(value);
        }
        public static long ToInt64(string value)
        {
            return System.Convert.ToInt64(value);
        }
        public static long ToInt64(uint value)
        {
            return System.Convert.ToInt64(value);
        }
        public static long ToInt64(ulong value)
        {
            return System.Convert.ToInt64(value);
        }
        public static long ToInt64(ushort value)
        {
            return System.Convert.ToInt64(value);
        }
        public static long ToInt64(object value, IFormatProvider provider)
        {
            return System.Convert.ToInt64(value, provider);
        }
        public static long ToInt64(string value, IFormatProvider provider)
        {
            return System.Convert.ToInt64(value, provider);
        }

        public static long ToInt64(string value, FromBase fromBase)
        {
            return System.Convert.ToInt64(value, (int)fromBase);
        }

        #region 下面的转换方法会在出现不能转换或错误时,使用默认值
        public static long ToInt64(string value, long defaultValue)
        {
            if (IsNull(value) || (value is string && string.IsNullOrWhiteSpace((string)value)))
            {
                return defaultValue;
            }
            try
            {
                return System.Convert.ToInt32(value);
            }
            catch
            {
                return defaultValue;
            }
        }

        public static long ToInt64(object value, long defaultValue)
        {
            if (IsNull(value) || (value is string && string.IsNullOrWhiteSpace((string)value)))
            {
                return defaultValue;
            }
            try
            {
                return System.Convert.ToInt32(value);
            }
            catch
            {
                return defaultValue;
            }
        }
        #endregion

        #region 下面的方法将字符串转换为可空类型
        public static Nullable<long> ToInt64(string value, long? defaultValue = 0)
        {
            return ToInt64(value, defaultValue, defaultValue);
        }
        public static Nullable<long> ToInt64(string value, long? nullValue = null, long? errorValue = 0)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                return nullValue;
            }
            try
            {
                return ToInt64(value);
            }
            catch
            {
                return errorValue;
            }
        }
        #endregion
        #endregion

        #region SBYTE
        public static sbyte ToSByte(bool value)
        {
            return System.Convert.ToSByte(value);
        }
        public static sbyte ToSByte(byte value)
        {
            return System.Convert.ToSByte(value);
        }
        public static sbyte ToSByte(char value)
        {
            return System.Convert.ToSByte(value);
        }
        public static sbyte ToSByte(DateTime value)
        {
            return System.Convert.ToSByte(value);
        }
        public static sbyte ToSByte(decimal value)
        {
            return System.Convert.ToSByte(value);
        }
        public static sbyte ToSByte(double value)
        {
            return System.Convert.ToSByte(value);
        }
        public static sbyte ToSByte(float value)
        {
            return System.Convert.ToSByte(value);
        }
        public static sbyte ToSByte(int value)
        {
            return System.Convert.ToSByte(value);
        }
        public static sbyte ToSByte(long value)
        {
            return System.Convert.ToSByte(value);
        }
        public static sbyte ToSByte(object value)
        {
            return System.Convert.ToSByte(value);
        }
        public static sbyte ToSByte(sbyte value)
        {
            return System.Convert.ToSByte(value);
        }
        public static sbyte ToSByte(short value)
        {
            return System.Convert.ToSByte(value);
        }
        public static sbyte ToSByte(string value)
        {
            return System.Convert.ToSByte(value);
        }
        public static sbyte ToSByte(uint value)
        {
            return System.Convert.ToSByte(value);
        }
        public static sbyte ToSByte(ulong value)
        {
            return System.Convert.ToSByte(value);
        }
        public static sbyte ToSByte(ushort value)
        {
            return System.Convert.ToSByte(value);
        }
        public static sbyte ToSByte(object value, IFormatProvider provider)
        {
            return System.Convert.ToSByte(value, provider);
        }
        public static sbyte ToSByte(string value, IFormatProvider provider)
        {
            return System.Convert.ToSByte(value, provider);
        }
        public static sbyte ToSByte(string value, int fromBase)
        {
            return System.Convert.ToSByte(value, fromBase);
        }

        #region 下面的转换方法会在出现不能转换或错误时,使用默认值
        public static sbyte ToInt64(object value, sbyte defaultValue)
        {
            if (IsNull(value) || (value is string && string.IsNullOrWhiteSpace((string)value)))
            {
                return defaultValue;
            }
            try
            {
                return System.Convert.ToSByte(value);
            }
            catch
            {
                return defaultValue;
            }
        }
        #endregion
        #endregion

        #region FLOAT
        public static float ToFloat(bool value)
        {
            return System.Convert.ToSingle(value);
        }
        public static float ToFloat(byte value)
        {
            return System.Convert.ToSingle(value);
        }
        public static float ToFloat(char value)
        {
            return System.Convert.ToSingle(value);
        }
        public static float ToFloat(DateTime value)
        {
            return System.Convert.ToSingle(value);
        }
        public static float ToFloat(decimal value)
        {
            return System.Convert.ToSingle(value);
        }
        public static float ToFloat(double value)
        {
            return System.Convert.ToSingle(value);
        }
        public static float ToFloat(float value)
        {
            return System.Convert.ToSingle(value);
        }
        public static float ToFloat(int value)
        {
            return System.Convert.ToSingle(value);
        }
        public static float ToFloat(long value)
        {
            return System.Convert.ToSingle(value);
        }
        public static float ToFloat(object value)
        {
            return System.Convert.ToSingle(value);
        }
        public static float ToFloat(sbyte value)
        {
            return System.Convert.ToSingle(value);
        }
        public static float ToFloat(short value)
        {
            return System.Convert.ToSingle(value);
        }
        public static float ToFloat(string value)
        {
            return System.Convert.ToSingle(value);
        }
        public static float ToFloat(uint value)
        {
            return System.Convert.ToSingle(value);
        }
        public static float ToFloat(ulong value)
        {
            return System.Convert.ToSingle(value);
        }
        public static float ToFloat(ushort value)
        {
            return System.Convert.ToSingle(value);
        }
        public static float ToFloat(object value, IFormatProvider provider)
        {
            return System.Convert.ToSingle(value, provider);
        }
        public static float ToFloat(string value, IFormatProvider provider)
        {
            return System.Convert.ToSingle(value, provider);
        }

        #region 下面的转换方法会在出现不能转换或错误时,使用默认值
        public static float ToSingle(object value, float defaultValue)
        {
            if (IsNull(value) || (value is string && string.IsNullOrWhiteSpace((string)value)))
            {
                return defaultValue;
            }
            try
            {
                return System.Convert.ToSingle(value);
            }
            catch
            {
                return defaultValue;
            }
        }
        #endregion

        #region 下面的方法将字符串转换为可空类型
        public static Nullable<float> ToFloat(string value, float? defaultValue = 0)
        {
            return ToFloat(value, defaultValue, defaultValue);
        }
        public static Nullable<float> ToFloat(string value, float? nullValue = null, float? errorValue = 0)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                return nullValue;
            }
            try
            {
                return ToFloat(value);
            }
            catch
            {
                return errorValue;
            }
        }
        #endregion
        #endregion

        #region STRING
        public static string ToString(bool value)
        {
            return System.Convert.ToString(value);
        }
        public static string ToString(byte value)
        {
            return System.Convert.ToString(value);
        }
        public static string ToString(char value)
        {
            return System.Convert.ToString(value);
        }
        /// <summary>
        /// 把一个时间格式化成字符串
        /// </summary>
        /// <param name="value">时间</param>
        /// <param name="format">格式化类型</param>
        /// <param name="minmaxexpr">当时间为最大值或最小值时的默认值</param>
        /// <returns></returns>
        public static string ToString(DateTime value, DateFormatType format = DateFormatType.DateTime, string minmaxexpr = "--")
        {
            return value.ToString(format, minmaxexpr);
        }
        public static string ToDateString(DateTime value, string minmaxexpr = "--")
        {
            return value.ToString(DateFormatType.Date, minmaxexpr);
        }
        public static string ToTimeString(DateTime value, string minmaxexpr = "--")
        {
            return value.ToString(DateFormatType.Time, minmaxexpr);
        }
        public static string ToDateTimeString(DateTime value, string minmaxexpr = "--")
        {
            return value.ToString(DateFormatType.DateTime, minmaxexpr);
        }
        public static string ToDateTimeString(object value, string minmaxexpr = "--")
        {
            if (value is DateTime)
            {
                return ((DateTime)value).ToString(DateFormatType.DateTime, minmaxexpr);
            }
            else
            {
                if (value is string)
                {
                    return ToDateTime((string)value).ToString(DateFormatType.DateTime, minmaxexpr);
                }
                return ToDateTime(value).ToString(DateFormatType.DateTime, minmaxexpr);
            }
        }
        public static string ToDateString(object value, string minmaxexpr = "--")
        {
            if (value is DateTime)
            {
                return ((DateTime)value).ToString(DateFormatType.Date, minmaxexpr);
            }
            else
            {
                if (value is string)
                {
                    return ToDateTime((string)value).ToString(DateFormatType.Date, minmaxexpr);
                }
                return ToDateTime(value).ToString(DateFormatType.Date, minmaxexpr);
            }
        }
        public static string ToTimeString(object value, string minmaxexpr = "--")
        {
            if (value is DateTime)
            {
                return ((DateTime)value).ToString(DateFormatType.Time, minmaxexpr);
            }
            else
            {
                if (value is string)
                {
                    return ToDateTime((string)value).ToString(DateFormatType.Time, minmaxexpr);
                }
                return ToDateTime(value).ToString(DateFormatType.Time, minmaxexpr);
            }
        }
        public static string ToString(object value, string nullvalue)
        {
            if (value == null)
            {
                return nullvalue;
            }
            if (value is string)
            {
                return string.IsNullOrWhiteSpace((string)value) ? nullvalue : (string)value;
            }
            if (value is DateTime)
            {
                return Convert.ToDateString((DateTime)value, nullvalue);
            }

            return Convert.ToString(value);
        }
        public static string ToString(decimal value)
        {
            return System.Convert.ToString(value);
        }
        public static string ToString(double value)
        {
            return System.Convert.ToString(value);
        }
        public static string ToString(float value)
        {
            return System.Convert.ToString(value);
        }
        public static string ToString(int value)
        {
            return System.Convert.ToString(value);
        }
        public static string ToString(long value)
        {
            return System.Convert.ToString(value);
        }
        public static string ToString(object value)
        {
            if (value is DateTime)
            {
                return ToString((DateTime)value);
            }
            return System.Convert.ToString(value);
        }
        public static string ToString(sbyte value)
        {
            return System.Convert.ToString(value);
        }
        public static string ToString(short value)
        {
            return System.Convert.ToString(value);
        }
        public static string ToString(string value)
        {
            return System.Convert.ToString(value);
        }
        public static string ToString(uint value)
        {
            return System.Convert.ToString(value);
        }
        public static string ToString(ulong value)
        {
            return System.Convert.ToString(value);
        }
        public static string ToString(ushort value)
        {
            return System.Convert.ToString(value);
        }
        public static string ToString(bool value, IFormatProvider provider)
        {
            return System.Convert.ToString(value, provider);
        }
        public static string ToString(byte value, IFormatProvider provider)
        {
            return System.Convert.ToString(value, provider);
        }
        public static string ToString(byte value, int toBase)
        {
            return System.Convert.ToString(value, toBase);
        }
        public static string ToString(char value, IFormatProvider provider)
        {
            return System.Convert.ToString(value, provider);
        }
        public static string ToString(DateTime value, IFormatProvider provider)
        {
            return System.Convert.ToString(value, provider);
        }
        public static string ToString(decimal value, IFormatProvider provider)
        {
            return System.Convert.ToString(value, provider);
        }
        public static string ToString(double value, IFormatProvider provider)
        {
            return System.Convert.ToString(value, provider);
        }
        public static string ToString(float value, IFormatProvider provider)
        {
            return System.Convert.ToString(value, provider);
        }
        public static string ToString(int value, IFormatProvider provider)
        {
            return System.Convert.ToString(value, provider);
        }
        public static string ToString(int value, int toBase)
        {
            return System.Convert.ToString(value, toBase);
        }
        public static string ToString(long value, IFormatProvider provider)
        {
            return System.Convert.ToString(value, provider);
        }
        public static string ToString(long value, int toBase)
        {
            return System.Convert.ToString(value, toBase);
        }
        public static string ToString(object value, IFormatProvider provider)
        {
            return System.Convert.ToString(value, provider);
        }
        public static string ToString(sbyte value, IFormatProvider provider)
        {
            return System.Convert.ToString(value, provider);
        }
        public static string ToString(short value, IFormatProvider provider)
        {
            return System.Convert.ToString(value, provider);
        }
        public static string ToString(short value, int toBase)
        {
            return System.Convert.ToString(value, toBase);
        }
        public static string ToString(string value, IFormatProvider provider)
        {
            return System.Convert.ToString(value, provider);
        }
        public static string ToString(uint value, IFormatProvider provider)
        {
            return System.Convert.ToString(value, provider);
        }
        public static string ToString(ulong value, IFormatProvider provider)
        {
            return System.Convert.ToString(value, provider);
        }
        public static string ToString(ushort value, IFormatProvider provider)
        {
            return System.Convert.ToString(value, provider);
        }
        public static string ToUnicode(string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return string.Empty;
            }
            byte[] bytes = System.Text.Encoding.Unicode.GetBytes(value);
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < bytes.Length; i += 2)
            {
                sb.Append(@"\u");
                sb.Append(bytes[i + 1].ToString("x2"));
                sb.Append(bytes[i].ToString("x2"));
            }
            return sb.ToString();
        }
        public static string FromUnicode(string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return string.Empty;
            }
            string v = value.Trim();
            if (Regular.CheckString(v, @"^(\\u?(\w{4}))*$", false, System.Text.RegularExpressions.RegexOptions.IgnoreCase))
            {
                System.Text.RegularExpressions.MatchCollection matchs = Regular.Matches(@"\\u?(\w{4})", v, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                StringBuilder sb = new StringBuilder();
                foreach (System.Text.RegularExpressions.Match match in matchs)
                {
                    byte[] bytes = new byte[] { (byte)Convert.ToInt32(match.Groups[1].Value.Substring(2), 16), (byte)Convert.ToInt32(match.Groups[1].Value.Substring(0, 2), 16) };
                    sb.Append(Encoding.Unicode.GetString(bytes));
                }
                return sb.ToString();
            }
            throw new Exception("输入的Unicode编码不正确");
        }
        public static string ToStrictString<T>(IEnumerable<T> values, Func<T, string> convert = null, string separator = ",")
        {
            if (convert == null)
            {
                return string.Join(separator, values);
            }
            StringBuilder sb = new StringBuilder();
            var itor = values.GetEnumerator();
            while (itor.MoveNext())
            {
                var item = itor.Current;
                if (item == null)
                {
                    continue;
                }
                if (sb.Length > 0)
                {
                    sb.Append(separator);
                }
                sb.Append(convert(item));
            }
            return sb.ToString();

        }
        public static string ToStrictString<T>(IEnumerable<T> values, int start, int length = 0, Func<T, string> convert = null, string separator = ",")
        {
            if (values == null)
            {
                return string.Empty;
            }
            StringBuilder sb = new StringBuilder();
            int pos = 0;
            var itor = values.GetEnumerator();
            while (pos < start && itor.MoveNext())
            {
                pos++;
            }
            if (length == 0)
            {
                while (itor.MoveNext())
                {
                    var item = itor.Current;
                    if (item == null)
                    {
                        continue;
                    }
                    if (sb.Length > 0)
                    {
                        sb.Append(separator);
                    }
                    sb.Append(convert != null ? convert(item) : item.ToString());
                }
            }
            else
            {
                while (pos < start + length && itor.MoveNext())
                {
                    pos++;
                    var item = itor.Current;
                    if (sb.Length > 0)
                    {
                        sb.Append(separator);
                    }
                    sb.Append(convert != null ? convert(item) : item.ToString());
                }
            }
            return sb.ToString();
        }
        public static List<T> FromStrictString<T>(string value, char separator = ',', Func<string, T> convert = null)
        {
            return new List<T>(value.Split(separator).ForEach(item => convert != null ? convert(item) : ChangeType<T>(item)));
        }

        /// <summary>
        /// 获取第一个不为空且长度大于0的字符串
        /// </summary>
        /// <param name="value">第一个字符串</param>
        /// <param name="values">其它字符串</param>
        /// <returns>返回第一个长度大于0的字符串,如果没有找到,返回String.Empty</returns>
        public static string GrubNotNullEmptyString(string value, params string[] values)
        {
            if (!string.IsNullOrEmpty(value))
            {
                return value;
            }
            foreach (var x in values)
            {
                if (!string.IsNullOrEmpty(x))
                {
                    return x;
                }
            }
            return string.Empty;
        }

        /// <summary>
        /// 获取第一个不为空且长度大于0且不为空格的字符串
        /// </summary>
        /// <param name="value">第一个字符串</param>
        /// <param name="values">其它字符串</param>
        /// <returns>返回第一个长度大于0且不为空格的字符串,如果没有找到,返回String.Empty</returns>
        public static string GrubNotNullWhiteSpaceString(string value, params string[] values)
        {
            if (!string.IsNullOrWhiteSpace(value))
            {
                return value;
            }
            foreach (var x in values)
            {
                if (!string.IsNullOrWhiteSpace(x))
                {
                    return x;
                }
            }
            return string.Empty;
        }

        /// <summary>
        /// 把一个字符串转换为使用Span标记的带有Title的HTML标记
        /// </summary>
        /// <param name="value">要显示的字符串</param>
        /// <param name="length">要显示的字节数</param>
        /// <returns></returns>
        public static string ToSpanTitleString(string value, int length = int.MaxValue)
        {
            if (value.Length * 2 <= length)
            {
                return string.Format("<span title=\"{0}\">{0}</span>", EncodeHtml(value));
            }
            else
            {
                return string.Format("<span title=\"{0}\">{1}</span>", EncodeHtml(value), EncodeHtml(ToEllipsisString(value, length)));
            }
        }

        /// <summary>
        /// 把一个字符串转换为一个带有省略号的字符串(如果字符串的长度超过定义的长度)
        /// </summary>
        /// <param name="value"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        public static string ToEllipsisString(string value, int length)
        {
            if (string.IsNullOrEmpty(value))
            {
                return string.Empty;
            }
            length -= 2;//先预留省略号的位置
            var pos = length / 2;//当前返回的字符串的位置,从返回长度的一半开始
            var curlen = value.Substring(0, pos + 1).Sum(c => c > 255 ? 2 : 1); //记录当前的字符串的字节长度
            for (var i = pos + 1; i < value.Length; i++)
            {
                curlen += value[i] > 255 ? 2 : 1;
                if (curlen <= length)
                {
                    pos++;
                }
                else
                {
                    //检查是否是只剩下一个字符,如果是则返回
                    return i + 1 == value.Length ? value : value.Substring(0, pos + 1) + "…";
                }
            }
            return value;
        }
        #endregion

        #region Nullable<T>
        /// <summary>
        /// 转换可空的结构体为字符串
        /// </summary>
        /// <typeparam name="T">结构体类型</typeparam>
        /// <param name="value">结构体的值</param>
        /// <param name="nvl">当结构体为null时,返回的表达式</param>
        /// <param name="convert">当结构体不为null时,使用这个方法转换结构体的值,如果不设置这个参数,则使用结构体的ToString()方法转换为字符串</param>
        /// <returns></returns>
        public static string ToString<T>(Nullable<T> value, string nvl = "", Func<T, string> convert = null) where T : struct
        {
            return value.HasValue ? (convert != null ? convert(value.Value) : value.Value.ToString()) : nvl;
        }
        public static Nullable<T> ToNullable<T>(string value) where T : struct
        {
            if (IsNullOrWhiteSpace(value))
            {
                return null;
            }
            return ChangeType<T>(value.Trim());
        }
        #endregion

        #region UINT16
        public static ushort ToUInt16(bool value)
        {
            return System.Convert.ToUInt16(value);
        }
        public static ushort ToUInt16(byte value)
        {
            return System.Convert.ToUInt16(value);
        }
        public static ushort ToUInt16(char value)
        {
            return System.Convert.ToUInt16(value);
        }
        public static ushort ToUInt16(DateTime value)
        {
            return System.Convert.ToUInt16(value);
        }
        public static ushort ToUInt16(decimal value)
        {
            return System.Convert.ToUInt16(value);
        }
        public static ushort ToUInt16(double value)
        {
            return System.Convert.ToUInt16(value);
        }
        public static ushort ToUInt16(float value)
        {
            return System.Convert.ToUInt16(value);
        }
        public static ushort ToUInt16(int value)
        {
            return System.Convert.ToUInt16(value);
        }
        public static ushort ToUInt16(long value)
        {
            return System.Convert.ToUInt16(value);
        }
        public static ushort ToUInt16(object value)
        {
            return System.Convert.ToUInt16(value);
        }
        public static ushort ToUInt16(sbyte value)
        {
            return System.Convert.ToUInt16(value);
        }
        public static ushort ToUInt16(short value)
        {
            return System.Convert.ToUInt16(value);
        }
        public static ushort ToUInt16(string value)
        {
            return System.Convert.ToUInt16(value);
        }
        public static ushort ToUInt16(uint value)
        {
            return System.Convert.ToUInt16(value);
        }
        public static ushort ToUInt16(ulong value)
        {
            return System.Convert.ToUInt16(value);
        }
        public static ushort ToUInt16(ushort value)
        {
            return System.Convert.ToUInt16(value);
        }
        public static ushort ToUInt16(object value, IFormatProvider provider)
        {
            return System.Convert.ToUInt16(value, provider);
        }
        public static ushort ToUInt16(string value, IFormatProvider provider)
        {
            return System.Convert.ToUInt16(value, provider);
        }
        public static ushort ToUInt16(string value, FromBase fromBase)
        {
            return System.Convert.ToUInt16(value, (int)fromBase);
        }

        #region 下面的转换方法会在出现不能转换或错误时,使用默认值
        public static ushort ToUInt16(string value, ushort defaultValue)
        {
            if (IsNull(value) || (value is string && string.IsNullOrWhiteSpace((string)value)))
            {
                return defaultValue;
            }
            try
            {
                return System.Convert.ToUInt16(value);
            }
            catch
            {
                return defaultValue;
            }
        }

        public static ushort ToInt16(object value, ushort defaultValue)
        {
            if (IsNull(value) || (value is string && string.IsNullOrWhiteSpace((string)value)))
            {
                return defaultValue;
            }
            try
            {
                return System.Convert.ToUInt16(value);
            }
            catch
            {
                return defaultValue;
            }
        }
        #endregion

        #region 下面的方法将字符串转换为可空类型
        public static Nullable<float> ToUInt16(string value, ushort? defaultValue = 0)
        {
            return ToUInt16(value, defaultValue, defaultValue);
        }
        public static Nullable<float> ToUInt16(string value, ushort? nullValue = null, ushort? errorValue = 0)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                return nullValue;
            }
            try
            {
                return ToUInt16(value);
            }
            catch
            {
                return errorValue;
            }
        }
        #endregion
        #endregion

        #region UINT32
        public static uint ToUInt32(bool value)
        {
            return System.Convert.ToUInt32(value);
        }
        public static uint ToUInt32(byte value)
        {
            return System.Convert.ToUInt32(value);
        }
        public static uint ToUInt32(char value)
        {
            return System.Convert.ToUInt32(value);
        }
        public static uint ToUInt32(DateTime value)
        {
            return System.Convert.ToUInt32(value);
        }
        public static uint ToUInt32(decimal value)
        {
            return System.Convert.ToUInt32(value);
        }
        public static uint ToUInt32(double value)
        {
            return System.Convert.ToUInt32(value);
        }
        public static uint ToUInt32(float value)
        {
            return System.Convert.ToUInt32(value);
        }
        public static uint ToUInt32(int value)
        {
            return System.Convert.ToUInt32(value);
        }
        public static uint ToUInt32(long value)
        {
            return System.Convert.ToUInt32(value);
        }
        public static uint ToUInt32(object value)
        {
            return System.Convert.ToUInt32(value);
        }
        public static uint ToUInt32(sbyte value)
        {
            return System.Convert.ToUInt32(value);
        }
        public static uint ToUInt32(short value)
        {
            return System.Convert.ToUInt32(value);
        }
        public static uint ToUInt32(string value)
        {
            return System.Convert.ToUInt32(value);
        }
        public static uint ToUInt32(uint value)
        {
            return System.Convert.ToUInt32(value);
        }
        public static uint ToUInt32(ulong value)
        {
            return System.Convert.ToUInt32(value);
        }
        public static uint ToUInt32(ushort value)
        {
            return System.Convert.ToUInt32(value);
        }
        public static uint ToUInt32(object value, IFormatProvider provider)
        {
            return System.Convert.ToUInt32(value, provider);
        }
        public static uint ToUInt32(string value, IFormatProvider provider)
        {
            return System.Convert.ToUInt32(value, provider);
        }
        public static uint ToUInt32(string value, FromBase fromBase)
        {
            return System.Convert.ToUInt32(value, (int)fromBase);
        }

        #region 下面的转换方法会在出现不能转换或错误时,使用默认值
        public static uint ToUInt32(string value, uint defaultValue)
        {
            if (IsNull(value) || (value is string && string.IsNullOrWhiteSpace((string)value)))
            {
                return defaultValue;
            }
            try
            {
                return System.Convert.ToUInt32(value);
            }
            catch
            {
                return defaultValue;
            }
        }

        public static uint ToInt32(object value, uint defaultValue)
        {
            if (IsNull(value) || (value is string && string.IsNullOrWhiteSpace((string)value)))
            {
                return defaultValue;
            }
            try
            {
                return System.Convert.ToUInt32(value);
            }
            catch
            {
                return defaultValue;
            }
        }
        #endregion

        #region 下面的方法将字符串转换为可空类型
        public static Nullable<uint> ToUInt32(string value, uint? defaultValue = 0)
        {
            return ToUInt32(value, defaultValue, defaultValue);
        }
        public static Nullable<uint> ToUInt32(string value, uint? nullValue = null, uint? errorValue = 0)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                return nullValue;
            }
            try
            {
                return ToUInt32(value);
            }
            catch
            {
                return errorValue;
            }
        }
        #endregion
        #endregion

        #region UINT64
        public static ulong ToUInt64(bool value)
        {
            return System.Convert.ToUInt64(value);
        }
        public static ulong ToUInt64(byte value)
        {
            return System.Convert.ToUInt64(value);
        }
        public static ulong ToUInt64(char value)
        {
            return System.Convert.ToUInt64(value);
        }
        public static ulong ToUInt64(DateTime value)
        {
            return System.Convert.ToUInt64(value);
        }
        public static ulong ToUInt64(decimal value)
        {
            return System.Convert.ToUInt64(value);
        }
        public static ulong ToUInt64(double value)
        {
            return System.Convert.ToUInt64(value);
        }
        public static ulong ToUInt64(float value)
        {
            return System.Convert.ToUInt64(value);
        }
        public static ulong ToUInt64(int value)
        {
            return System.Convert.ToUInt64(value);
        }
        public static ulong ToUInt64(long value)
        {
            return System.Convert.ToUInt64(value);
        }
        public static ulong ToUInt64(object value)
        {
            return System.Convert.ToUInt64(value);
        }
        public static ulong ToUInt64(sbyte value)
        {
            return System.Convert.ToUInt64(value);
        }
        public static ulong ToUInt64(short value)
        {
            return System.Convert.ToUInt64(value);
        }
        public static ulong ToUInt64(string value)
        {
            return System.Convert.ToUInt64(value);
        }
        public static ulong ToUInt64(uint value)
        {
            return System.Convert.ToUInt64(value);
        }
        public static ulong ToUInt64(ulong value)
        {
            return System.Convert.ToUInt64(value);
        }
        public static ulong ToUInt64(ushort value)
        {
            return System.Convert.ToUInt64(value);
        }
        public static ulong ToUInt64(object value, IFormatProvider provider)
        {
            return System.Convert.ToUInt64(value, provider);
        }
        public static ulong ToUInt64(string value, IFormatProvider provider)
        {
            return System.Convert.ToUInt64(value, provider);
        }
        public static ulong ToUInt64(string value, FromBase fromBase)
        {
            return System.Convert.ToUInt64(value, (int)fromBase);
        }

        #region 下面的转换方法会在出现不能转换或错误时,使用默认值
        public static ulong ToUInt64(string value, ulong defaultValue)
        {
            if (IsNull(value) || (value is string && string.IsNullOrWhiteSpace((string)value)))
            {
                return defaultValue;
            }
            try
            {
                return System.Convert.ToUInt64(value);
            }
            catch
            {
                return defaultValue;
            }
        }

        public static ulong ToUInt64(object value, ulong defaultValue)
        {
            if (IsNull(value) || (value is string && string.IsNullOrWhiteSpace((string)value)))
            {
                return defaultValue;
            }
            try
            {
                return System.Convert.ToUInt64(value);
            }
            catch
            {
                return defaultValue;
            }
        }
        #endregion

        #region 下面的方法将字符串转换为可空类型
        public static Nullable<ulong> ToUInt64(string value, ulong? defaultValue = 0)
        {
            return ToUInt64(value, defaultValue, defaultValue);
        }
        public static Nullable<ulong> ToUInt64(string value, ulong? nullValue = null, ulong? errorValue = 0)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                return nullValue;
            }
            try
            {
                return ToUInt64(value);
            }
            catch
            {
                return errorValue;
            }
        }
        #endregion
        #endregion

        #region ENUM
        /// <summary>
        /// 把一个枚举类型的成员转换为枚举列表
        /// </summary>
        /// <param name="enumType">枚举类型</param>
        /// <param name="excludes">要排除的成员</param>
        /// <returns></returns>
        public static List<EnumItem> ListEnum(Type enumType, params  Enum[] excludes)
        {
            if (!enumType.IsEnum)
            {
                throw new Exception("给定的类型不是枚举类型");
            }
            List<EnumItem> result = new List<EnumItem>();
            foreach (System.Enum em in Enum.GetValues(enumType))
            {
                int value = Convert.ToInt32(em);
                if (excludes.Length > 0 && excludes.Any(item => Convert.ToInt32(item) == value))
                {
                    continue;
                }
                result.Add(new EnumItem() { Name = em.ToString(), Value = value, Text = em.GetDescription() });
            }
            return result;
        }

        public static List<EnumItem> ListEnum(Enum enumItem, params  Enum[] others)
        {
            List<EnumItem> result = new List<EnumItem>();

            result.Add(new EnumItem() { Name = enumItem.ToString(), Value = Convert.ToInt32(enumItem), Text = enumItem.GetDescription() });
            foreach (System.Enum em in others)
            {
                result.Add(new EnumItem() { Name = em.ToString(), Value = Convert.ToInt32(em), Text = em.GetDescription() });
            }
            return result;
        }

        [Serializable]
        public class EnumItem
        {
            public string Name { get; set; }
            public string Text { get; set; }
            public int Value { get; set; }
        }
        #endregion

        #region GUID
        public static Guid ToGuid(string value)
        {
            return Guid.Parse(value);
        }
        public static Guid ToGuid(string value, Guid defaultValue)
        {
            var result = defaultValue;
            Guid.TryParse(value, out result);
            return result;
        }
        #endregion

        #region XML序列化与反序列化
        /// <summary>
        /// 把一个对象进行XML序列化 
        /// </summary>
        /// <param name="o">要序列化的对象</param>
        /// <returns>序列化后的数据流</returns>
        public static string ToXml(object o)
        {
            return ToXml(o, null, System.Text.Encoding.UTF8);
        }

        /// <summary>
        /// 把一个对象进行XML序列化 
        /// </summary>
        /// <param name="o">要序列化的对象</param>
        /// <param name="encoding">序列化后的XML流的encoding</param>
        /// <returns>序列化后的数据流</returns>
        public static string ToXml(object o, Encoding encoding)
        {
            return ToXml(o, (XmlSerializerNamespaces)null, encoding);
        }

        /// <summary>
        /// 把一个对象进行XML序列化 
        /// </summary>
        /// <param name="o">要序列化的对象</param>
        /// <param name="namespaces">命名空间</param>
        /// <returns>序列化后的数据流</returns>
        public static string ToXml(object o, XmlSerializerNamespaces namespaces)
        {
            return ToXml(o, namespaces, System.Text.Encoding.UTF8);
        }

        /// <summary>
        /// 把一个对象进行XML序列化 
        /// </summary>
        /// <param name="o">要序列化的对象</param>
        /// <param name="namespaces">命名空间</param>
        /// <param name="encoding">序列化后的XML流的encoding</param>
        /// <returns>序列化后的数据流</returns>
        public static string ToXml(object o, XmlSerializerNamespaces namespaces, Encoding encoding)
        {
            if (o is DataTable && string.IsNullOrWhiteSpace(((DataTable)o).TableName))
            {
                ((DataTable)o).TableName = "DataTable";
            }
            XmlSerializer formatter = new XmlSerializer(o.GetType());
            MemoryStream ms = new MemoryStream();
            using (StreamWriter writer = new StreamWriter(ms, encoding))
            {
                formatter.Serialize(writer, o, namespaces);
                writer.Close();
            }
            return encoding.GetString(ms.ToArray()).Trim();
        }

        /// <summary>
        /// 把一个XML格式的数据反序列化,返回反序列化后的对象
        /// </summary>
        /// <param name="xml">要反序列化的XML数据</param>
        /// <returns>反序列化后的对象</returns>
        public static T FromXml<T>(string xml)
        {
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml);
            XmlNodeReader xmlReader = new XmlNodeReader(doc.DocumentElement);
            XmlSerializer serializer = new XmlSerializer(typeof(T));
            return (T)serializer.Deserialize(xmlReader);
        }

        public static T FromXml<T>(Stream stream)
        {
            XmlSerializer formatter = new XmlSerializer(typeof(T));
            return (T)formatter.Deserialize(stream);
        }
        #endregion

        #region JSON序列化与反序列化
        /// <summary>
        /// 把一个对象进行JSON序列化
        /// </summary>
        /// <param name="o">要序列化的对象</param>
        /// <returns>序列化后的对象</returns>
        public static string ToJson(object o)
        {
            return Newtonsoft.Json.JsonConvert.SerializeObject(o);
        }

        /// <summary>
        /// 把一个对象进行JSON序列化
        /// </summary>
        /// <param name="o">要序列化的对象</param>
        /// <param name="formatting">格式化样式,缩进或不缩进</param>
        /// <returns>序列化后的对象</returns>
        public static string ToJson(object o, Newtonsoft.Json.Formatting formatting)
        {
            return Newtonsoft.Json.JsonConvert.SerializeObject(o, formatting);
        }

        /// <summary>
        /// 把一个对象进行JSON序列化
        /// </summary>
        /// <param name="o">要序列化的对象</param>
        /// <param name="converters"></param>
        /// <returns>序列化后的对象</returns>
        public static string ToJson(object o, params Newtonsoft.Json.JsonConverter[] converters)
        {
            return Newtonsoft.Json.JsonConvert.SerializeObject(o, converters);
        }

        /// <summary>
        /// 把一个对象进行JSON序列化
        /// </summary>
        /// <param name="o">要序列化的对象</param>
        /// <param name="formatting">格式化样式,缩进或不缩进</param>
        /// <param name="settings"></param>
        /// <returns>序列化后的对象</returns>
        public static string ToJson(object o, Newtonsoft.Json.Formatting formatting, Newtonsoft.Json.JsonSerializerSettings settings)
        {
            return Newtonsoft.Json.JsonConvert.SerializeObject(o, formatting, settings);
        }

        /// <summary>
        /// 把一个对象进行JSON序列化
        /// </summary>
        /// <param name="o">要序列化的对象</param>
        /// <param name="formatting">格式化样式,缩进或不缩进</param>
        /// <param name="converters"></param>
        /// <returns>序列化后的对象</returns>
        public static string ToJson(object o, Newtonsoft.Json.Formatting formatting, params Newtonsoft.Json.JsonConverter[] converters)
        {
            return Newtonsoft.Json.JsonConvert.SerializeObject(o, formatting, converters);
        }

        /// <summary>
        /// 把一个字符串进行JSON反序列化
        /// </summary>
        /// <typeparam name="T">要反序列化的对象的类型</typeparam>
        /// <param name="value">要反序列化的对象的原始字符串</param>
        /// <returns>反序列化后的对象</returns>
        public static T FromJson<T>(string value)
        {
            return (T)Newtonsoft.Json.JsonConvert.DeserializeObject<T>(value);
        }

        /// <summary>
        /// 把一个字符串进行JSON反序列化
        /// </summary>
        /// <typeparam name="T">要反序列化的对象的类型</typeparam>
        /// <param name="value">要反序列化的对象的原始字符串</param>
        /// <param name="settings"></param>
        /// <returns>反序列化后的对象</returns>
        public static T FromJson<T>(string value, Newtonsoft.Json.JsonSerializerSettings settings)
        {
            return (T)Newtonsoft.Json.JsonConvert.DeserializeObject<T>(value, settings);
        }

        /// <summary>
        /// 把一个字符串进行JSON反序列化
        /// </summary>
        /// <typeparam name="T">要反序列化的对象的类型</typeparam>
        /// <param name="value">要反序列化的对象的原始字符串</param>
        /// <param name="converters"></param>
        /// <returns>反序列化后的对象</returns>
        public static T FromJson<T>(string value, params Newtonsoft.Json.JsonConverter[] converters)
        {
            return (T)Newtonsoft.Json.JsonConvert.DeserializeObject<T>(value, converters);
        }

        /// <summary>
        /// 把一个字符串进行JSON反序列化
        /// </summary>
        /// <param name="value">要反序列化的对象的原始字符串</param>
        /// <returns>反序列化后的对象</returns>
        public static object FromJson(string value)
        {
            return Newtonsoft.Json.JsonConvert.DeserializeObject(value);
        }

        /// <summary>
        /// 把一个字符串进行JSON反序列化
        /// </summary>
        /// <param name="value">要反序列化的对象的原始字符串</param>
        /// <param name="type">要反序列化的对象的类型</param>
        /// <returns>反序列化后的对象</returns>
        public static object FromJson(string value, Type type)
        {
            return Newtonsoft.Json.JsonConvert.DeserializeObject(value, type);
        }

        /// <summary>
        /// 把一个字符串进行JSON反序列化
        /// </summary>
        /// <param name="value">要反序列化的对象的原始字符串</param>
        /// <param name="type">要反序列化的对象的类型</param>
        /// <param name="settings"></param>
        /// <returns>反序列化后的对象</returns>
        public static object FromJson(string value, Type type, Newtonsoft.Json.JsonSerializerSettings settings)
        {
            return Newtonsoft.Json.JsonConvert.DeserializeObject(value, type, settings);
        }

        /// <summary>
        /// 把一个字符串进行JSON反序列化
        /// </summary>
        /// <param name="value">要反序列化的对象的原始字符串</param>
        /// <param name="type">要反序列化的对象的类型</param>
        /// <param name="converters"></param>
        /// <returns>反序列化后的对象</returns>
        public static object FromJson(string value, Type type, params Newtonsoft.Json.JsonConverter[] converters)
        {
            return Newtonsoft.Json.JsonConvert.DeserializeObject(value, type, converters);
        }
        #endregion

        #region HTML编码
        public static string EncodeHtml(string value)
        {
            return System.Web.HttpUtility.HtmlEncode(value ?? string.Empty);
        }
        public static string DecodeHtml(string value)
        {
            return System.Web.HttpUtility.HtmlDecode(value ?? string.Empty);
        }
        #endregion

        #region XML格式化

        public static string FormatXml(string value, int indent = 2)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                return string.Empty;
            }
            if (indent < 0)
            {
                indent = 2;
            }
            XmlDocument xmlDoc = new XmlDocument();
            using (System.IO.StringWriter sw = new System.IO.StringWriter())
            using (XmlTextWriter writer = new XmlTextWriter(sw))
            {
                writer.Indentation = indent;
                writer.Formatting = Formatting.Indented;
                xmlDoc.LoadXml(value.Trim());
                xmlDoc.WriteContentTo(writer);
                writer.Close();
                return sw.ToString();
            }
        }

        public static string FormatXml(XmlDocument value, int indent = 2)
        {
            if (value == null)
            {
                return string.Empty;
            }
            if (indent < 0)
            {
                indent = 2;
            }
            using (System.IO.StringWriter sw = new System.IO.StringWriter())
            using (XmlTextWriter writer = new XmlTextWriter(sw))
            {
                writer.Indentation = indent;
                writer.Formatting = Formatting.Indented;
                value.WriteContentTo(writer);
                writer.Close();
                return sw.ToString();
            }
        }
        #endregion

        #region URL编码
        public static string EncodeUrl(string value)
        {
            return System.Web.HttpUtility.UrlEncode(value ?? string.Empty);
        }

        public static string DecodeUrl(string value)
        {
            return System.Web.HttpUtility.UrlDecode(value ?? string.Empty);
        }
        #endregion

        #region JS:escape
        public static string EncodeUnicodeUrl(string value)
        {
            return System.Web.HttpUtility.UrlEncodeUnicode(value);
        }

        public static string DecodeUnicodeUrl(string value)
        {
            return System.Web.HttpUtility.UrlDecode(value ?? string.Empty);
        }
        #endregion

        #region BitConverter
        public static long DoubleToInt64Bits(double value)
        {
            return BitConverter.DoubleToInt64Bits(value);
        }
        public static byte[] GetBytes(bool value)
        {
            return BitConverter.GetBytes(value);
        }
        public static byte[] GetBytes(char value)
        {
            return BitConverter.GetBytes(value);
        }
        public static byte[] GetBytes(double value)
        {
            return BitConverter.GetBytes(value);
        }
        public static byte[] GetBytes(float value)
        {
            return BitConverter.GetBytes(value);
        }
        public static byte[] GetBytes(int value)
        {
            return BitConverter.GetBytes(value);
        }
        public static byte[] GetBytes(long value)
        {
            return BitConverter.GetBytes(value);
        }
        public static byte[] GetBytes(short value)
        {
            return BitConverter.GetBytes(value);
        }
        public static byte[] GetBytes(uint value)
        {
            return BitConverter.GetBytes(value);
        }
        public static byte[] GetBytes(ulong value)
        {
            return BitConverter.GetBytes(value);
        }
        public static byte[] GetBytes(ushort value)
        {
            return BitConverter.GetBytes(value);
        }
        public static double Int64BitsToDouble(long value)
        {
            return BitConverter.Int64BitsToDouble(value);
        }
        public static bool ToBoolean(byte[] value, int startIndex)
        {
            return BitConverter.ToBoolean(value, startIndex);
        }
        public static char ToChar(byte[] value, int startIndex)
        {
            return BitConverter.ToChar(value, startIndex);
        }
        public static double ToDouble(byte[] value, int startIndex)
        {
            return BitConverter.ToDouble(value, startIndex);
        }
        public static short ToInt16(byte[] value, int startIndex)
        {
            return BitConverter.ToInt16(value, startIndex);
        }
        public static int ToInt32(byte[] value, int startIndex)
        {
            return BitConverter.ToInt32(value, startIndex);
        }
        public static long ToInt64(byte[] value, int startIndex)
        {
            return BitConverter.ToInt64(value, startIndex);
        }
        public static float ToSingle(byte[] value, int startIndex)
        {
            return BitConverter.ToSingle(value, startIndex);
        }
        public static string ToString(byte[] value)
        {
            return BitConverter.ToString(value);
        }
        public static string ToString(byte[] value, int startIndex)
        {
            return BitConverter.ToString(value, startIndex);
        }
        public static string ToString(byte[] value, int startIndex, int length)
        {
            return BitConverter.ToString(value, startIndex);
        }
        public static ushort ToUInt16(byte[] value, int startIndex)
        {
            return BitConverter.ToUInt16(value, startIndex);
        }
        public static uint ToUInt32(byte[] value, int startIndex)
        {
            return BitConverter.ToUInt32(value, startIndex);
        }
        public static ulong ToUInt64(byte[] value, int startIndex)
        {
            return BitConverter.ToUInt64(value, startIndex);
        }
        #endregion

        #region EncodingConvert
        public static byte[] ChangeEncoding(byte[] bytes, Encoding src, Encoding dst)
        {
            return System.Text.Encoding.Convert(src, dst, bytes);
        }

        public static byte[] ChangeEncoding(byte[] bytes, Encoding src, Encoding dst, int index, int count)
        {
            return System.Text.Encoding.Convert(src, dst, bytes, index, count);
        }
        #endregion

        #region 计算HASH
        #region MD5
        public static string ToMD5(string value)
        {
            return BitConverter.ToString(HashCompute(System.Text.Encoding.UTF8.GetBytes(value), "MD5")).Replace("-", "");
        }
        public static string ToMD5(byte[] value)
        {
            return BitConverter.ToString(HashCompute(value, "MD5")).Replace("-", "");
        }
        public static string ToMD5(Stream value)
        {
            return BitConverter.ToString(HashCompute(value, "MD5")).Replace("-", "");
        }
        #endregion

        #region  RIPEMD160
        public static string ToRIPEMD160(string value)
        {
            return BitConverter.ToString(HashCompute(System.Text.Encoding.UTF8.GetBytes(value), "RIPEMD160")).Replace("-", "");
        }
        public static string ToRIPEMD160(byte[] value)
        {
            return BitConverter.ToString(HashCompute(value, "RIPEMD160")).Replace("-", "");
        }
        public static string ToRIPEMD160(Stream value)
        {
            return BitConverter.ToString(HashCompute(value, "RIPEMD160")).Replace("-", "");
        }
        #endregion

        #region SHA1
        public static string ToSHA1(string value)
        {
            return BitConverter.ToString(HashCompute(System.Text.Encoding.UTF8.GetBytes(value), "SHA1")).Replace("-", "");
        }
        public static string ToSHA1(byte[] value)
        {
            return BitConverter.ToString(HashCompute(value, "SHA1")).Replace("-", "");
        }
        public static string ToSHA1(Stream value)
        {
            return BitConverter.ToString(HashCompute(value, "SHA1")).Replace("-", "");
        }
        #endregion

        #region SHA256
        public static string ToSHA256(string value)
        {
            return BitConverter.ToString(HashCompute(System.Text.Encoding.UTF8.GetBytes(value), "SHA256")).Replace("-", "");
        }
        public static string ToSHA256(byte[] value)
        {
            return BitConverter.ToString(HashCompute(value, "SHA256")).Replace("-", "");
        }
        public static string ToSHA256(Stream value)
        {
            return BitConverter.ToString(HashCompute(value, "SHA256")).Replace("-", "");
        }
        #endregion

        #region SHA384
        public static string ToSHA384(string value)
        {
            return BitConverter.ToString(HashCompute(System.Text.Encoding.UTF8.GetBytes(value), "SHA384")).Replace("-", "");
        }
        public static string ToSHA384(byte[] value)
        {
            return BitConverter.ToString(HashCompute(value, "SHA384")).Replace("-", "");
        }
        public static string ToSHA384(Stream value)
        {
            return BitConverter.ToString(HashCompute(value, "SHA384")).Replace("-", "");
        }
        #endregion

        #region SHA512
        public static string ToSHA512(string value)
        {
            return BitConverter.ToString(HashCompute(System.Text.Encoding.UTF8.GetBytes(value), "SHA512")).Replace("-", "");
        }
        public static string ToSHA512(byte[] value)
        {
            return BitConverter.ToString(HashCompute(value, "SHA512")).Replace("-", "");
        }
        public static string SHA512Compute(Stream value)
        {
            return BitConverter.ToString(HashCompute(value, "SHA512")).Replace("-", "");
        }
        #endregion

        #region CRC32
        public static string ToCRC(string value)
        {
            return ToCRC(System.Text.Encoding.UTF8.GetBytes(value));
        }
        public static string ToCRC(byte[] value)
        {
            return ToCRC(new MemoryStream(value));
        }
        public static string ToCRC(Stream value)
        {
            UInt32 crc = 0xFFFFFFFF;
            for (int i = 0; i < value.Length; i++)
            {
                crc = ((crc >> 8) & 0x00FFFFFF) ^ crcTable[(crc ^ value.ReadByte()) & 0xFF];
            }
            UInt32 temp = crc ^ 0xFFFFFFFF;
            return Convert.ToString(((int)temp), 16);
        }
        #endregion
        #endregion

        #region 对称加密
        #region DES
        public static string ToDES(string value, string password, byte[] iv = null, CipherMode cipher = CipherMode.CBC, PaddingMode padding = PaddingMode.PKCS7)
        {
            MemoryStream inms = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(value));
            MemoryStream outms = new MemoryStream();
            SymmetricEncrypt(inms, System.Text.Encoding.UTF8.GetBytes(password), defaultDESIV, "DES", cipher, padding, outms);
            return Convert.ToBase64String(outms.ToArray());
        }

        public static string FromDES(string value, string password, byte[] iv = null, CipherMode cipher = CipherMode.CBC, PaddingMode padding = PaddingMode.PKCS7)
        {
            MemoryStream inms = new MemoryStream(Convert.FromBase64String(value));
            MemoryStream outms = new MemoryStream();
            SymmetricDecrypt(inms, System.Text.Encoding.UTF8.GetBytes(password), iv ?? defaultDESIV, "DES", cipher, padding, outms);
            return System.Text.Encoding.UTF8.GetString(outms.ToArray());
        }
        #endregion

        #region TripleDES
        public static string ToTripleDES(string value, string password, byte[] iv = null, CipherMode cipher = CipherMode.CBC, PaddingMode padding = PaddingMode.PKCS7)
        {
            MemoryStream inms = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(value));
            MemoryStream outms = new MemoryStream();
            SymmetricEncrypt(inms, System.Text.Encoding.UTF8.GetBytes(password), iv ?? defaultTDESIV, "TripleDES", cipher, padding, outms);
            return Convert.ToBase64String(outms.ToArray());
        }

        public static string FromTripleDES(string value, string password, byte[] iv = null, CipherMode cipher = CipherMode.CBC, PaddingMode padding = PaddingMode.PKCS7)
        {
            MemoryStream inms = new MemoryStream(Convert.FromBase64String(value));
            MemoryStream outms = new MemoryStream();
            SymmetricDecrypt(inms, System.Text.Encoding.UTF8.GetBytes(password), iv ?? defaultTDESIV, "TripleDES", cipher, padding, outms);
            return System.Text.Encoding.UTF8.GetString(outms.ToArray());
        }
        #endregion

        #region RC2
        public static string ToRC2(string value, string password, byte[] iv = null, CipherMode cipher = CipherMode.CBC, PaddingMode padding = PaddingMode.PKCS7)
        {
            MemoryStream inms = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(value));
            MemoryStream outms = new MemoryStream();
            SymmetricEncrypt(inms, System.Text.Encoding.UTF8.GetBytes(password), iv ?? defaultRC2IV, "RC2", cipher, padding, outms);
            return Convert.ToBase64String(outms.ToArray());
        }
        public static string FromRC2(string value, string password, byte[] iv = null, CipherMode cipher = CipherMode.CBC, PaddingMode padding = PaddingMode.PKCS7)
        {
            MemoryStream inms = new MemoryStream(Convert.FromBase64String(value));
            MemoryStream outms = new MemoryStream();
            SymmetricDecrypt(inms, System.Text.Encoding.UTF8.GetBytes(password), iv ?? defaultRC2IV, "TripleDES", cipher, padding, outms);
            return System.Text.Encoding.UTF8.GetString(outms.ToArray());
        }
        #endregion

        #region Rijndael
        public static string ToRijndael(string value, string password, byte[] iv = null, CipherMode cipher = CipherMode.CBC, PaddingMode padding = PaddingMode.PKCS7)
        {
            MemoryStream inms = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(value));
            MemoryStream outms = new MemoryStream();
            SymmetricEncrypt(inms, System.Text.Encoding.UTF8.GetBytes(password), iv ?? defaultRC2IV, "Rijndael", cipher, padding, outms);
            return Convert.ToBase64String(outms.ToArray());
        }

        public static string FromRijndael(string value, string password, byte[] iv = null, CipherMode cipher = CipherMode.CBC, PaddingMode padding = PaddingMode.PKCS7)
        {
            MemoryStream inms = new MemoryStream(Convert.FromBase64String(value));
            MemoryStream outms = new MemoryStream();
            SymmetricDecrypt(inms, System.Text.Encoding.UTF8.GetBytes(password), iv ?? defaultRC2IV, "Rijndael", cipher, padding, outms);
            return System.Text.Encoding.UTF8.GetString(outms.ToArray());
        }
        #endregion
        #endregion

        #region 非对称加密
        public static byte[] ToRSA(byte[] value, RSAParameters key)
        {
            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
            rsa.ImportParameters(key);
            bool fOAEP = true;
            //如果不是WindowsXP及以上的版本,把fOAEP设置为false.否则使用默认值
            if (!(Environment.OSVersion.Platform == PlatformID.Win32NT &&
                    (Environment.OSVersion.Version.Major >= 6 ||
                    (Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor >= 1))
                 )
               )
            {
                fOAEP = false;
            }
            return rsa.Encrypt(value, fOAEP);

        }

        public static byte[] FromRSA(byte[] value, RSAParameters key)
        {
            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
            rsa.ImportParameters(key);
            bool fOAEP = true;
            //如果不是WindowsXP及以上的版本,把fOAEP设置为false.否则使用默认值
            if (!(Environment.OSVersion.Platform == PlatformID.Win32NT &&
                   (Environment.OSVersion.Version.Major >= 6 ||
                   (Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor >= 1))
                   )
                )
            {
                fOAEP = false;
            }

            return rsa.Decrypt(value, fOAEP);
        }
        #endregion

        #region 私有方法
        #region 计算HASH
        private static byte[] HashCompute(byte[] input, string type)
        {
            HashAlgorithm ha = HashAlgorithm.Create(type);
            byte[] tmp = ha.ComputeHash(input);
            ha.Clear();
            return tmp;
        }
        private static byte[] HashCompute(Stream input, string type)
        {
            HashAlgorithm ha = HashAlgorithm.Create(type);
            byte[] tmp = ha.ComputeHash(input);
            ha.Clear();
            return tmp;
        }

        static byte[] defaultDESIV = new byte[] { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
        static byte[] defaultRC2IV = new byte[] { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
        static byte[] defaultRijndaelIV = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 };
        static byte[] defaultTDESIV = new byte[] { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };

        static UInt32[] crcTable = {   
             0x0, 0x77073096, 0xee0e612c, 0x990951ba, 0x76dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
             0xedb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x9b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
             0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
             0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
             0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
             0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
             0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
             0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
             0x76dc4190, 0x1db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x6b6b51f, 0x9fbfe4a5, 0xe8b8d433,
             0x7807c9a2, 0xf00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x86d3d2d, 0x91646c97, 0xe6635c01,
             0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
             0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
             0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
             0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
             0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
             0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
             0xedb88320, 0x9abfb3b6, 0x3b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x4db2615, 0x73dc1683,
             0xe3630b12, 0x94643b84, 0xd6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0xa00ae27, 0x7d079eb1,
             0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
             0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
             0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
             0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
             0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
             0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
             0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x26d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x5005713,
             0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0xcb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0xbdbdf21,
             0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
             0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
             0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
             0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
             0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
             0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,
            };
        #endregion

        #region 对称加密
        private static void SymmetricEncrypt(Stream input, byte[] key, byte[] iv, string type, CipherMode mode, PaddingMode padding, Stream output)
        {
            using (SymmetricAlgorithm sa = SymmetricAlgorithm.Create(type))
            {
                sa.Mode = mode;
                sa.Padding = padding;
                CryptoStream cst = new CryptoStream(output, sa.CreateEncryptor(key, iv), CryptoStreamMode.Write);
                byte[] buffer = new byte[2048];
                int len = 0;
                len = input.Read(buffer, 0, buffer.Length);
                while (len > 0)
                {
                    cst.Write(buffer, 0, len);
                    len = input.Read(buffer, 0, buffer.Length);
                }
                cst.Close();
                input.Close();
            }
        }

        private static void SymmetricDecrypt(Stream input, byte[] key, byte[] iv, string type, CipherMode mode, PaddingMode padding, Stream output)
        {
            using (SymmetricAlgorithm sa = SymmetricAlgorithm.Create(type))
            {
                sa.Mode = mode;
                sa.Padding = padding;
                CryptoStream cst = new CryptoStream(input, sa.CreateDecryptor(key, iv), CryptoStreamMode.Read);
                byte[] buffer = new byte[2048];
                int len = 0;
                len = cst.Read(buffer, 0, buffer.Length);
                while (len > 0)
                {
                    output.Write(buffer, 0, len);
                    len = cst.Read(buffer, 0, buffer.Length);
                }
                input.Close();
                output.Close();
            }
        }

        #endregion
        #endregion

        #region 使用GZIPSTREAM压缩与解压缩
        public static string Compress(string value)
        {
            return value.Compress();
        }
        public static string Decompress(string value)
        {
            return value.Decompress();
        }
        #endregion

        #region 转换为用千分位分隔的数字
        [Description("转换为千分位数字，第二个参数表示保留小数位数")]
        public static string ToComma(object value, string defaultValue = "-", int digits = 0)
        {
            if (value == null || value == DBNull)
            {
                return defaultValue;
            }
            try
            {
                return string.Format(string.Format("{{0:N{0}}}", digits), value);
            }
            catch
            {
                return defaultValue;
            }
        }
        [Description("转换为带小数的数字，第二个参数表示保留小数位数")]
        public static string ToDigits(object value, string defaultValue = "-", int digits = 0)
        {
            if (value == null || value == DBNull)
            {
                return defaultValue;
            }
            try
            {
                return string.Format(string.Format("{{0:F{0}}}", digits), value);
            }
            catch
            {
                return defaultValue;
            }
        }
        #endregion

        [Description("获取枚举类型的扩展属性")]
        public static string GetDescription(System.Enum em)
        {
            return em.GetDescription();
        }

        [Description("获取枚举类型的扩展属性")]
        public static T GetAttribute<T>(System.Enum em)
            where T : System.Attribute
        {
            return em.GetAttribute<T>();
        }
    }

    public enum DateFormatType
    {
        /// <summary>
        /// 日期
        /// </summary>
        [System.ComponentModel.Description("yyyy-MM-dd")]
        Date,
        /// <summary>
        /// 时间
        /// </summary>
        [System.ComponentModel.Description("HH:mm:ss")]
        Time,
        /// <summary>
        /// 日期时间
        /// </summary>
        [System.ComponentModel.Description("yyyy-MM-dd HH:mm:ss")]
        DateTime
    }

    public enum DayOfWeek
    {

        /// <summary>
        /// 表示星期日。
        /// </summary>
        [Description("星期日")]
        Sunday = 0,

        /// <summary>
        /// 表示星期一。
        /// </summary>
        [Description("星期一")]
        Monday = 1,

        /// <summary>
        /// 表示星期二。
        /// </summary>
        [Description("星期二")]
        Tuesday = 2,

        /// <summary>
        /// 表示星期三。
        /// </summary>
        [Description("星期三")]
        Wednesday = 3,

        /// <summary>
        /// 表示星期四。
        /// </summary>
        [Description("星期四")]
        Thursday = 4,

        /// <summary>
        /// 表示星期五。
        /// </summary>
        [Description("")]
        Friday = 5,

        /// <summary>
        /// 表示星期六。
        /// </summary>
        [Description("星期六")]
        Saturday = 6,

    }

    public enum FromBase
    {
        [Description("二进制")]
        B = 2,

        [Description("八进制")]
        O = 8,

        [Description("十进制")]
        D = 10,

        [Description("十六进制")]
        H = 16
    }
}
namespace Newtonsoft.Json.Converters
{
    [System.ComponentModel.Description("把时间转换成以[yyyy-MM-dd]格式化的字符串")]
    public class DateConverter : Newtonsoft.Json.Converters.IsoDateTimeConverter
    {
        public DateConverter()
        {
            base.DateTimeFormat = "yyyy-MM-dd";
        }
    }

    [System.ComponentModel.Description("把时间转换成以[yyyy-MM-dd HH:mm:ss]格式化的字符串")]
    public class DateTimeConverter : Newtonsoft.Json.Converters.IsoDateTimeConverter
    {
        public DateTimeConverter()
        {
            base.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
        }
    }

    public abstract class NumberConverter : Newtonsoft.Json.JsonConverter
    {
        public virtual string ValueFormat { get; set; }

        public override bool CanConvert(Type objectType)
        {
            return objectType == typeof(int)
                || objectType == typeof(int?)
                || objectType == typeof(decimal)
                || objectType == typeof(decimal?)
                || objectType == typeof(short)
                || objectType == typeof(short?)
                || objectType == typeof(long)
                || objectType == typeof(long?)
                || objectType == typeof(float)
                || objectType == typeof(float?)
                || objectType == typeof(double)
                || objectType == typeof(double?)
                || objectType == typeof(uint)
                || objectType == typeof(uint?)
                || objectType == typeof(ushort)
                || objectType == typeof(ushort?)
                || objectType == typeof(ulong)
                || objectType == typeof(ulong?);
        }

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            return reader.Value;
        }

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (value == null)
            {
                writer.WriteNull();
                return;
            }
            if (string.IsNullOrWhiteSpace(ValueFormat))
            {
                writer.WriteValue(value);
                return;
            }
            dynamic v = value;
            writer.WriteValue(string.Format(ValueFormat, value));
        }
    }

    #region 千分位
    [System.ComponentModel.Description("千分位")]
    public class NumberConverterComma0F : NumberConverter
    {
        private string _ValueFormat = "{0:N0}";
        public override string ValueFormat { get { return this._ValueFormat; } set { this._ValueFormat = value; } }
    }

    [System.ComponentModel.Description("千分位,一位小数")]
    public class NumberConverterComma1F : NumberConverter
    {
        private string _ValueFormat = "{0:N1}";
        public override string ValueFormat { get { return this._ValueFormat; } set { this._ValueFormat = value; } }
    }

    [System.ComponentModel.Description("千分位,两位小数")]
    public class NumberConverterComma2F : NumberConverter
    {
        private string _ValueFormat = "{0:N2}";
        public override string ValueFormat { get { return this._ValueFormat; } set { this._ValueFormat = value; } }
    }

    [System.ComponentModel.Description("千分位,三位小数")]
    public class NumberConverterComma3F : NumberConverter
    {
        private string _ValueFormat = "{0:N3}";
        public override string ValueFormat { get { return this._ValueFormat; } set { this._ValueFormat = value; } }
    }

    [System.ComponentModel.Description("千分位,四位小数")]
    public class NumberConverterComma4F : NumberConverter
    {
        private string _ValueFormat = "{0:N4}";
        public override string ValueFormat { get { return this._ValueFormat; } set { this._ValueFormat = value; } }
    }

    [System.ComponentModel.Description("千分位,五位小数")]
    public class NumberConverterComma5F : NumberConverter
    {
        private string _ValueFormat = "{0:N5}";
        public override string ValueFormat { get { return this._ValueFormat; } set { this._ValueFormat = value; } }
    }

    [System.ComponentModel.Description("千分位,六位小数")]
    public class NumberConverterComma6F : NumberConverter
    {
        private string _ValueFormat = "{0:N6}";
        public override string ValueFormat { get { return this._ValueFormat; } set { this._ValueFormat = value; } }
    }
    #endregion

    #region 小数
    [System.ComponentModel.Description("无小数")]
    public class NumberConverter0F : NumberConverter
    {
        private string _ValueFormat = "{0:F0}";
        public override string ValueFormat { get { return this._ValueFormat; } set { this._ValueFormat = value; } }
    }

    [System.ComponentModel.Description("一位小数")]
    public class NumberConverter1F : NumberConverter
    {
        private string _ValueFormat = "{0:F1}";
        public override string ValueFormat { get { return this._ValueFormat; } set { this._ValueFormat = value; } }
    }

    [System.ComponentModel.Description("两位小数")]
    public class NumberConverter2F : NumberConverter
    {
        private string _ValueFormat = "{0:F2}";
        public override string ValueFormat { get { return this._ValueFormat; } set { this._ValueFormat = value; } }
    }

    [System.ComponentModel.Description("三位小数")]
    public class NumberConverter3F : NumberConverter
    {
        private string _ValueFormat = "{0:F3}";
        public override string ValueFormat { get { return this._ValueFormat; } set { this._ValueFormat = value; } }
    }

    [System.ComponentModel.Description("四位小数")]
    public class NumberConverter4F : NumberConverter
    {
        private string _ValueFormat = "{0:F4}";
        public override string ValueFormat { get { return this._ValueFormat; } set { this._ValueFormat = value; } }
    }

    [System.ComponentModel.Description("五位小数")]
    public class NumberConverter5F : NumberConverter
    {
        private string _ValueFormat = "{0:F5}";
        public override string ValueFormat { get { return this._ValueFormat; } set { this._ValueFormat = value; } }
    }

    [System.ComponentModel.Description("六位小数")]
    public class NumberConverter6F : NumberConverter
    {
        private string _ValueFormat = "{0:F6}";
        public override string ValueFormat { get { return this._ValueFormat; } set { this._ValueFormat = value; } }
    }

    #endregion
}